<template>
  <div id="app" class="main">
    <router-view v-if='isRouterAlive' />
  </div>
</template>


<script>
import Bottom from "./components/Bottom";
import store from "./store";

export default {
  components: {Bottom},

  data () {
    return {
      isRouterAlive: true
    }
  },

  methods: {
    reload () {
      this.isRouterAlive = false
      this.$nextTick(() => {
        this.isRouterAlive = true
      })
    },

    _isMobile() {
      let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
      return flag;
    },

  },

  provide () {
    return {
      reload: this.reload
    }
  },

  mounted: function () {

    const token = localStorage.getItem("token")
    const userinfo = store.getters.getUser;
    if (token) { // 判断当前的token是否存在 ； 登录存入的token
      // console.log('已登陆')
      if (!userinfo) {
        //由于sessionStorage的原因可能userinfo不存在
        this.$axios.get("/user/getUserByJWT").then(res => {
          const userinfo = res.data.data //后端返回的登录用户信息（不包含密码）
          this.$store.commit("SET_USERINFO", userinfo)
        })
      }
    }

    // if (this._isMobile()) {
    //   // alert("手机端");
    //   console.log('手机端')
    //   this.$router.replace('/mindex');
    // } else {
    //   console.log('pc端')
    //   // this.$router.replace('/pc');
    //   this.$router.replace('/blogs');
    // }


    // //vue 关闭浏览器清空token （区分刷新）
    // //https://blog.csdn.net/huhuhuja/article/details/111475264
    // let beginTime = 0; //开始时间
    // let differTime = 0; //时间差
    // window.onunload = function () {
    //   differTime = new Date().getTime() - beginTime;
    //   if (differTime <= 5) {
    //     console.log("这是关闭");
    //     localStorage.setItem("token", "");
    //     sessionStorage.setItem("userinfo", "");
    //     //退出登录跳到首页
    //     this.$router.push({path: "/"});
    //   } else {
    //     console.log("这是刷新");
    //   }
    // };
    // window.onbeforeunload = function () {
    //   beginTime = new Date().getTime();
    // };
  }
}
</script>


<style>
/*@import "./mobile/font-style/font.css";*/


#app {
  /*text-align: center;*/
  /*font-family: PingFangBold;*/
  /*max-width: 1860px;*/
  width: 100%;
  margin: 0;
}





</style>